package tsing.javase.thread.automic;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author Tsing/吴清平
 * @Date 2022/12/28 11:38
 * @Version 1.0
 */
public class AutomicDemo {

    public static void main(String[] args) {

        long time = System.currentTimeMillis();
        System.out.println(time);

        ExecutorService exc = Executors.newFixedThreadPool(5);
        exc.execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10 ; i++) {
                    AutomicThread automicThread = new AutomicThread();
                     new Thread(automicThread).start();
                }
            }
        });

        exc.shutdown();



        while(true){
            System.out.println(AutomicThread.getAi());
            if(AutomicThread.getAi()%2!=0){
                System.out.println("error");
            }
        }










    }

}



class AutomicThread implements  Runnable{

    private    static AtomicInteger  ai = new AtomicInteger(0);

    @Override
    public void run() {
        ai.addAndGet(2);
    }


    public static Integer getAi(){
        return ai.get();
    }

}
